<?php

namespace Application\Sonata\UserBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class UserType extends AbstractType
{
    /**
     * @param FormBuilderInterface $builder
     * @param array $options
     */
    public function buildForm(FormBuilderInterface $builder, array $options)
    {        
        $builder
            ->add('username', 'text', array(
                'label' => "Pseudo",
                'required' => true,
            ))
            ->add('email', 'email', array(
                'label' => "Email",
                'required' => true,
            ))
            ->add('plain_password', 'repeated', array(
                'type' => 'password',
                'invalid_message' => 'Les deux mots de passe ne sont pas identiques',
                'options' => array('attr' => array('class' => 'password-field')),
                'required' => true,
                'first_options'  => array('label' => 'Mot de passe'),
                'second_options' => array('label' => 'Répétez le mot de passe'),
            ))
            ->add('dateOfBirth', 'date', array(
                'label'  => 'Date de naissance',
                'widget' => 'single_text',
                'format' => 'dd/MM/yyyy',
                'attr' => array(
                    'placeholder' => 'dd/mm/yyyy'
                )
            ))
            ->add('gender', 'choice', array(
                'label'        => 'Sexe',
                'expanded'     => true,
                'choices'      => array('m' => 'Masculin', 'f' => 'Féminin'),
                'widget_type'  => 'inline'
            ))
            ->add('gamme', 'entity', array(
                'label' => 'Votre budget',
                'class' => 'YCommerceGlobalBundle:Gamme',
            ))
            ->add('humeur', 'entity', array(
                'label' => 'Votre humeur',
                'class' => 'YCommerceGlobalBundle:Humeur',
            ))
            ->add('interets', 'entity', array(
                'label' => 'Vos centres d\'intérêts',
                'class' => 'YCommerceGlobalBundle:Interet',
                'multiple' => true,
                'expanded' => true
            ))
        ;
    }
    
    /**
     * @param OptionsResolverInterface $resolver
     */
    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'data_class' => 'Application\Sonata\UserBundle\Entity\User',
            'show_legend' => false
        ));
    }

    /**
     * @return string
     */
    public function getName()
    {
        return 'application_sonata_userbundle_user';
    }
}
